﻿<%@ WebHandler Language="C#" Class="StreamImage" %>

using System;
using System.Web;
using System.IO;

public class StreamImage : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        string filePath = context.Request.QueryString["TempFileLocation"].ToString();

        if (filePath == null || filePath == "")
        {
            context.Response.End();
        }

        byte[] imageData = GetImage(filePath);

        context.Response.ContentType = "image/jpeg";
        context.Response.BinaryWrite(imageData);
        context.Response.Flush();
    }

    private byte[] GetImage(string filePath)
    {
        using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        using (BinaryReader br = new BinaryReader(fs))
        {
            byte[] imageData = br.ReadBytes((int)br.BaseStream.Length);
            
            return imageData;
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}